package com.linzelin.www.util;

import com.linzelin.www.po.Association;
import com.linzelin.www.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class AccountAssociation {
    private static JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
    //添加社团用的方法
    public static void AssoicationAdd(Association association)
    {
        String sql = "insert into association values (null,?,?)";
        int count = template.update(sql,association.getName(),association.getContent());
        //将社团内容输入到表格中
        if(count>0)
        {
            System.out.println("输入成功");
        }
        else
        {
            System.out.println("输入失败");
        }
    }

    //展示社团
    public static void DisplayAssociation()
    {
        //用于展示已经有的社团的
        String sql = "select * from association";
        List<Association> list = template.query(sql,new BeanPropertyRowMapper<Association>(Association.class));
        for (Association as : list) {
            System.out.println("社团id:"+as.getId()+"--社团:"+as.getName()+"\n社团简介:"+as.getContent());
        }
    }

    //寻找符合要求的社团id
    public static void FindAssociation(Integer id)
    {
        String sql = "select * from association where id ="+id+"";
        List<Association> list = template.query(sql,new BeanPropertyRowMapper<Association>(Association.class));
        for (Association as : list) {
            System.out.println("社团id:"+as.getId()+"--社团:"+as.getName()+"\n社团简介:"+as.getContent());
        }
    }
}
